const generator = require('@babel/generator').default; // 将 AST 还原成 JavaScript 代码
const parse = require("@babel/parser");                // 编译成语法树
const traverse = require("@babel/traverse").default;   // 对语法树进行操作
const types = require("@babel/types");                  // 判断、验证节点的类型、构建新 AST 节点等
const fs = require("fs");                               // 读取文件

const File1 = process.argv.length > 2 ? process.argv[2] : './encode.js';
const File2 = process.argv.length > 3 ? process.argv[3] : './decode.js';

const jscode = fs.readFileSync(File1, {encoding: 'utf-8'});
const ast = parse.parse(jscode, {sourceType: "module"});



const {code} = generator(ast);
console.log(code);
fs.writeFile(File2, code, (err) => {
    if (err) throw err;
    console.log(`File has been saved as `);
});




